package com.td.framework.kqxt.pbgl.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.td.framework.common.AbstractAction;
import com.td.framework.kqxt.domain.KqGlpb;
import com.td.framework.kqxt.domain.KqGlpbxx;
import com.td.framework.kqxt.pbgl.service.GlpbService;
import com.td.framework.webmanager.page.PageService;

/**
 * 规律排班
 * @author smartzjp
 *
 */
public class GlpbAction extends AbstractAction {
	//实体对象
    private KqGlpb  kqGlpb;
    private List<KqGlpbxx> kqGlpbxxList =new ArrayList<KqGlpbxx>();; 
    //规律排班设置对象集合
    private List<KqGlpb> kqGlpbList;
    private List kqBcszList;
    private GlpbService glpbService;
    //查询条件
    private Log log = LogFactory.getLog(GlpbAction.class);
    
    //=======================================================排班列表 	START======================================
    /**
     * 人员排班列表集合
     * @return
     */
    public String listGlpb(){
    	String hql ="from KqGlpb";    	
    	int rows = this.getBaseService().getRowsByListHql(hql);				
		page = PageService.getPage(rows, currentPage, pageSize, pageMethod);
		this.setCurrentPage(page.getCurentPage());		
		this.setPageSize(page.getPageSize());
		kqGlpbList =this.getBaseService().getPageList(hql,page.getStartRow(),pageSize);
		return "listGlpb";
    }
    
    /**
     * 打开规律排班添加页面
     */
    public String createGlpbForm(){
    	kqBcszList = this.getGlpbService().getAllBc();
    	return "createGlpb";
    }
    
    /**
     * 添加规律排班信息
     * @return
     */
    public String createGlpb(){
	   boolean flag = false;
		try {
			/*String pyzt = ChineseTools.getFirstLetter(kqGlpb.getBcmc());
			kqGlpb.setPyzt(pyzt);*/
			kqGlpb.setCjr(getUserInfo().getYhm());
			kqGlpb.setCjsj(new Date());
			flag = this.getGlpbService().saveOrUpdateEntity(kqGlpb,kqGlpbxxList);
		} catch (Exception e) {
			 log.error("增加规律排班信息失败：",e);
			 this.handleMessage("info", "添加失败,联系管理员!");
		}
		if(flag = true){
	    	 this.handleMessage("info", "添加成功，请继续操作!");
	     }
	     return "toCreateForm";
    }
    
    /**
     *打开修改页面 
     * @return
     */
    public String reworkGlpbForm(){
    	kqGlpb = (KqGlpb) this.getBaseService().getEntityById(KqGlpb.class,zids[0]);
    	kqGlpbxxList = this.getGlpbService().getGlpbxxList(zids[0]+"");
    	return "reworkGlpb";
    }
    
    /**
     * 修改代码表信息
     * @return
     */
    public String reworkGlpb(){
    	 boolean flag = false;
 		try {
 			kqGlpb.setXgr(getUserInfo().getYhm());
			kqGlpb.setXgsj(new Date());
 			flag = this.getBaseService().saveOrUpdate(kqGlpb);
 		} catch (Exception e) {
 			log.error("修改规律排班设置失败：",e);
 			 this.handleMessage("info", "修改失败,请联系管理员!");
 		}
 	     if(flag = true){
 	    	 this.handleMessage("info", "修改成功!");
 	     }
 	     return "reworGlpb"; 
    }
    
    /**
     * 删除选中规律排班的信息
     * @return
     */
    public String removeGlpb(){
    	 boolean flag = false;
  	     flag = this.getBaseService().deleteBatch(KqGlpb.class, zids);
  	     return "listGlpb"; 
    }
    
    /**
     *打开规律排班设置展现页面
     * @return
     */
    public String showRypb(){
    	kqGlpb = (KqGlpb) this.getBaseService().getEntityById(KqGlpb.class,zids[0]);
    	return "showGlpb";
    }

	public KqGlpb getKqGlpb() {
		return kqGlpb;
	}

	public void setKqGlpb(KqGlpb kqGlpb) {
		this.kqGlpb = kqGlpb;
	}

	public List<KqGlpb> getKqGlpbList() {
		return kqGlpbList;
	}

	public void setKqGlpbList(List<KqGlpb> kqGlpbList) {
		this.kqGlpbList = kqGlpbList;
	}

	public List getKqBcszList() {
		return kqBcszList;
	}

	public void setKqBcszList(List kqBcszList) {
		this.kqBcszList = kqBcszList;
	}

	public GlpbService getGlpbService() {
		return glpbService;
	}

	public void setGlpbService(GlpbService glpbService) {
		this.glpbService = glpbService;
	}

	public List<KqGlpbxx> getKqGlpbxxList() {
		return kqGlpbxxList;
	}

	public void setKqGlpbxxList(List<KqGlpbxx> kqGlpbxxList) {
		this.kqGlpbxxList = kqGlpbxxList;
	}
	
	
}
